import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routers'
import ViewUI from 'view-design'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const router = new VueRouter({
  routes
})

/**
 * 路由前置拦截
 */
router.beforeEach((to, from, next) => {
  // 加载进度条
  ViewUI.LoadingBar.start()
  if(to.name === 'main'){
    next({name: 'home'})
  }else{
    next()
  }

})

/**
 * 路由后置拦截
 */
router.afterEach(route => {
  ViewUI.LoadingBar.finish()
})

export default router
